import {
  Column,
  CreateDateColumn,
  Entity,
  JoinTable,
  ManyToMany,
  ManyToOne,
  PrimaryGeneratedColumn,
  UpdateDateColumn,
} from 'typeorm';
import { User } from '../../user/entities/user.entity';
import { Menu } from '../../menu/entities/menu.entity';

@Entity('sys_role')
export class Role {
  @PrimaryGeneratedColumn('uuid')
  id: string;
  @Column({ type: 'varchar', comment: '角色名', unique: true })
  name: string;
  @Column({ type: 'varchar', comment: '角色编号' })
  serial: string;
  @Column({
    type: 'int',
    comment: '删除标记 0-未删除 1-删除',
    name: 'is_delete',
    default: 0,
  })
  isDelete: number;
  @CreateDateColumn({
    type: 'timestamp',
    name: 'create_date',
    comment: '创建时间',
  })
  createDate: Date;

  @UpdateDateColumn({
    type: 'timestamp',
    name: 'update_date',
    comment: '更新时间',
  })
  updateDate: Date;
  @ManyToOne((type) => User, (user) => user.roles, { eager: true })
  user: User;
  @ManyToOne((type) => User, (user) => user.roles, { eager: true })
  updateUser: User;
  @ManyToMany((type) => Menu, (menu) => menu.role)
  @JoinTable()
  menu: Menu[];
}
